package com.openvas.controller;

import java.util.List;
//    import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.openvas.commons.common.annotation.Log;
import com.openvas.commons.common.enums.BusinessType;
import com.openvas.domain.TableHost;
import com.openvas.service.ITableHostService;
import com.openvas.commons.common.core.controller.BaseController;
import com.openvas.commons.common.core.domain.AjaxResult;

import com.openvas.commons.common.core.page.TableDataInfo;

/**
 * 主键Controller
 * 
 * @author ruoyi
 * @date 2021-11-04
 */
@Controller
@RequestMapping("/api/host")
public class TableHostController extends BaseController
{
    private String prefix = "system/host";

    @Autowired
    private ITableHostService tableHostService;

   // //  @RequiresPermissions("system:host:view")
    @GetMapping()
    public String host()
    {
        return prefix + "/host";
    }

    /**
     * 查询主键列表
     */
   // //  @RequiresPermissions("system:host:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TableHost tableHost)
    {
        startPage();
        List<TableHost> list = tableHostService.selectTableHostList(tableHost);
        return getDataTable(list);
    }

    /**
     * 导出主键列表
     */
   // //  @RequiresPermissions("system:host:export")
    @Log(title = "主键", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TableHost tableHost)
    {
        List<TableHost> list = tableHostService.selectTableHostList(tableHost);
//        ExcelUtil<TableHost> util = new ExcelUtil<TableHost>(TableHost.class);
//        return util.exportExcel(list, "主键数据");
        return null;
    }

    /**
     * 新增主键
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存主键
     */
   // //  @RequiresPermissions("system:host:add")
    @Log(title = "主键", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TableHost tableHost)
    {
        return toAjax(tableHostService.insertTableHost(tableHost));
    }

    /**
     * 修改主键
     */
    @GetMapping("/edit/{assetId}")
    public String edit(@PathVariable("assetId") String assetId, ModelMap mmap)
    {
        TableHost tableHost = tableHostService.selectTableHostByAssetId(assetId);
        mmap.put("tableHost", tableHost);
        return prefix + "/edit";
    }

    /**
     * 修改保存主键
     */
   // //  @RequiresPermissions("system:host:edit")
    @Log(title = "主键", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TableHost tableHost)
    {
        return toAjax(tableHostService.updateTableHost(tableHost));
    }

    /**
     * 删除主键
     */
   // //  @RequiresPermissions("system:host:remove")
    @Log(title = "主键", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tableHostService.deleteTableHostByAssetIds(ids));
    }
}
